import 'dart:convert';
import 'package:flutter/material.dart';
import 'package:qaun_ni_dev/utils/request.dart';
import 'package:qaun_ni_dev/utils/toast.dart';
import 'package:qaun_ni_dev/model/brushModel.dart';


class BrushProvider with ChangeNotifier {

  List<BrushData> brushDataList = [];
  int page = 1;
  var videoUrl= '';


  getBrushList(context) async {
    page = 1;
    brushDataList = [];
    var formData = {
      'currentPage': page
    };

    await requestPost(context, '/ssl/sslPostList',formData: formData).then((value){
      var res = json.decode(value.toString());
      var tempData = BrushHappyModel.fromJson(res);
      if(tempData.data != null) {
        brushDataList = tempData.data;
      }
    });
    notifyListeners();
  }

  getBrushMoreList(context) async {
    page++;
    var formData = {
      'currentPage': page
    };
    await requestPost(context, '/ssl/sslPostList',formData: formData).then((value){
      var res = json.decode(value.toString());
      var tempData = BrushHappyModel.fromJson(res);
      if(tempData.data != null ) {
        var tempDatass = tempData.data;
        brushDataList.addAll(tempDatass);
      } else {
        Toast.toast(context,msg: '已经没有更多数据了哦！');
      }
    });
    notifyListeners();
  }

  setVideoTag(context,userId,val) async{
    var formData = {
      'postId': userId,
      'tag': val
    };
    if(val == 'SSL') {
      await requestPost(context, '/ssl/postTag',formData: formData).then((value){
        var res = json.decode(value.toString());
        if(res['code'] == 200) {
          Toast.toast(context,msg:'标记已设置为添加');
          Navigator.pushNamed(context, '/brushTag');
        }
      });
    } else if (val == 'SSN') {
      await requestPost(context, '/ssl/postTag',formData: formData).then((value){
        var res = json.decode(value.toString());
        if(res['code'] == 200) {
          Toast.toast(context,msg:'标记已设置为屏蔽');
          Navigator.pushNamed(context, '/brushTag');
        }
      });
    }
    notifyListeners();
  }

  getVideoStUrl (str) {
    videoUrl = str;
    notifyListeners();
  }
}

